﻿package bdz.common.string{
	import flash.events.EventDispatcher;
	import flash.utils.*;
	dynamic class RandomStringSequence extends EventDispatcher {
		private var current;
		private var inter:Number;
		private var str:String;
		private var speed:Number;
		private var fc:String;
		function RandomStringSequence(s:String, count:Number, ref:Object, prop:String, sp:Number, _fc:String) {
			fc = _fc;
			current = 0;
			speed = sp;
			str = s;
			inter = setInterval(mx.utils.Delegate.create(this, generator), speed, current, count+5, ref, prop);
		}
		private function generator(current, count, ref, prop) {
			if (current<count) {
				clearInterval(inter);
				if (current>3) {
					ref[prop] = getRandomString();
				} else {
					ref[prop] = (fc) ? fc : "-";
				}
				current = current+1;
				inter = setInterval(mx.utils.Delegate.create(this, generator), speed, current, count, ref, prop);
				return;
			} else {
				clearInterval(inter);
				ref[prop] = str;
				delete this;
			}
		}
		private function getRandomString():String {
			return String.fromCharCode(Math.random() * 50 + 64);
		}
	}
}